﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Manage_basisset_SysSetDetail : AdminPageBase
{
    int id;
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckAdmin();
     
        GetUserPermisions();
        GetSysSetId();
        if (!IsPostBack)
        {
           
            GetSysSetInfo();
         
        }
    }
    protected void CheckAdmin()
    {
        if (AdminSessionHelper.UserDetails == null)
        {
            JsHelper.TopAlertRedirect("请先登录", "../login.aspx", this.Page);
        }
    }

    protected void GetSysSetInfo()
    {
        if (id != 0)
        {
            DataSet ds = new DataSet();
            ds = jtDataAccess.GetSysSetDetail(id);
            if (CoreTools.CheckDataSet(ds))
            {
                this.GridView1.DataSource = ds.Tables[0];
                this.GridView1.DataBind();
            }
           
        }

    }

    protected void GetSysSetId()
    {
        if (Request.QueryString["id"] == null)
        {
            id = 0; 
        }
        else
        {
            id = Convert.ToInt32(Request.QueryString["id"]);
          
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //首先判断是否是数据行
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FCFDEE'");
            //当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
        }
        if (edit == 1)
            ((CommandField)GridView1.Columns[7]).ShowEditButton = true;
        else
            ((CommandField)GridView1.Columns[7]).ShowEditButton = false;
        if (delete == 1)
            ((CommandField)GridView1.Columns[7]).ShowDeleteButton = false;
        else
            ((CommandField)GridView1.Columns[7]).ShowDeleteButton = false;
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        GetSysSetInfo();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        GetSysSetInfo();
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        int flag = 0;
        int SysSetDetailId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
        int SysSetId = Convert.ToInt32(((HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdfSysSetId")).Value);
        TextBox txtValue1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtValue1");
        string Value1 = txtValue1.Text.Trim();
        if (Value1!= ""&& (!CoreTools.ProcessSqlStr(Value1, 0)))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
            txtValue1.Focus();
        }
        TextBox txtValue2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtValue2");
        string Value2 = txtValue2.Text.Trim();
        if (Value2 != "" && (!CoreTools.ProcessSqlStr(Value2, 0)))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
            txtValue2.Focus();
        }
        TextBox txtValue3 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtValue3");
        string Value3 = txtValue3.Text.Trim();
        if (Value3 != "" && (!CoreTools.ProcessSqlStr(Value3, 0)))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
            txtValue3.Focus();
        }
        TextBox txtValue4 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtValue4");
        string Value4 = txtValue4.Text.Trim();
        if (Value4 != "" && (!CoreTools.ProcessSqlStr(Value4, 0)))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
            txtValue4.Focus();
        }
        TextBox txtValue5 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtValue5");
        string Value5 = txtValue5.Text.Trim();
        if (Value5 != "" && (!CoreTools.ProcessSqlStr(Value5, 0)))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
            txtValue5.Focus();
        }
        flag = jtDataAccess.SetSysSetDetail(SysSetDetailId, Value1, Value2, Value3, Value4, Value5);

        switch (flag)
        {
            case 1:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("保存成功！"), false);
                break;
            case 0:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("保存失败，请重试！"), false);
                break;
            default:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("保存失败！"), false);

                break;
        }
        GridView1.EditIndex = -1;
        GetSysSetInfo();
    }
   
    protected void btnreturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("SysSet.aspx?MenuId="+MenuId);
    }
}